﻿using System;
using Entities.DataBase.Persistent;

namespace Entities.DataBase.Obj {

    public class PackageUpdator {
        
        public int CourierId { get; set; }

        public int Type { get; set; }

        public string Recipient { get; set; }

        public string Reference { get; set; }

        public string Description { get; set; }

        public string ShippingAddress { get; set; }

        public string PhoneNumber { get; set; }

        public string TrackingId { get; set; }

        public DateTime? DateCreated { get; set; }

        public void Update(Package package) {
            package.DateUpdated = DateTime.UtcNow;
            if (Type != package.Type) {
                package.Type = Type;
            }

            if (CourierId != package.CourierId) {
                package.CourierId = CourierId;
            }

            if (!string.IsNullOrEmpty(Recipient) && !package.Recipient.Equals(Recipient)) {
                 package.Recipient = Recipient;
            }

            if (!string.IsNullOrEmpty(ShippingAddress) && !package.ShippingAddress.Equals(ShippingAddress)) {
                 package.ShippingAddress = ShippingAddress;
            }

            if (!string.IsNullOrEmpty(PhoneNumber) && !package.PhoneNumber.Equals(PhoneNumber)) {
                package.PhoneNumber = PhoneNumber;
            }

            if (!string.IsNullOrEmpty(TrackingId) && !package.TrackingId.Equals(TrackingId)) {
                package.TrackingId = TrackingId;
            }
            if (!string.IsNullOrEmpty(Description) && !package.Data.Equals(Description)) {
                package.Description = Description;
            }
            if (DateCreated != null) {
                var date = (DateTime)DateCreated;
                if (date.Date.CompareTo(package.DateCreated.Date) != 0) {
                    package.DateCreated = (DateTime)DateCreated;
                }
                
            }

        }

    }
}